package com.example.studyplanning.controller;

import com.example.studyplanning.services.LogServices;
import com.example.studyplanning.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("log")
public class LogController {
    @Autowired
    private LogServices logServices;

    //查询日志信息
    @GetMapping("/list")
    public Result findAllLog(@RequestParam("adminID") Integer adminID){
        Result result = new Result();
        result.setCode(200);
        result.setMessage("查询成功");
        result.setObject(logServices.findAllLog(adminID));
        return result;
    };

    //插入日志信息
    @GetMapping("/add")
    public Result insertLog(@RequestParam("logContent") String logContent,
                            @RequestParam("adminID") Integer adminID)
    {
        Result result = new Result();
        int i = logServices.insertLog(logContent,adminID);
        if(i==1){
            result.setCode(200);
            result.setMessage("添加成功");
        }else{
            result.setCode(400);
            result.setMessage("添加失败");
        }
        return result;
    }

    //删除日志信息
    @GetMapping("/del")
    public Result DelLog(@RequestParam("logID") Integer logID){
        Result result = new Result();
        int i = logServices.DelLog(logID);
        if (i==1){
            result.setCode(200);
            result.setMessage("删除成功");
        }else {
            result.setCode(400);
            result.setMessage("删除失败");
        }
        return result;
    };

}
